
import UIKit

class XSBaseViewController: UITableViewController, XSRegiestViewDelegate {

    // MARK: - 属性
    var regiest = false
    
    override func loadView()
    {
        regiest == true ? super.loadView() : setupRegiestView()
    }
    
    func setupRegiestView()
    {
        self.view = regiestView
        
        regiestView.delegate = self
        
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "regiestBtnDidClick")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "loginBtnDidClick")
    }
    
    override func viewDidLoad()
    {
        super.viewDidLoad()
        
        if self is XSHomeViewController
        {
            self.regiestView.addAnimation()
           
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil)
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didBecomeActive", name: UIApplicationDidBecomeActiveNotification, object: nil)
        }
        else if self is XSDiscoveViewController
        {
            self.regiestView.changeRegiestView("visitordiscover_image_message", title: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }
        else if self is XSMessageViewController
        {
            self.regiestView.changeRegiestView("visitordiscover_image_message", title: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }
        else if self is XSProfileViewController
        {
            self.regiestView.changeRegiestView("visitordiscover_image_profile", title: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
    }
    
    // MARK: - XSRegiestViewDelegate代理方法
    func regiestBtnDidClick()
    {
        
    }
    
    func loginBtnDidClick()
    {
        let oauthVC = XSOAuthController()
        self.presentViewController(XSNavigationViewController(rootViewController: oauthVC), animated: true, completion: nil)
    }
    
    // MARK: - 通知方法
    
    func didBecomeActive()
    {
        self.regiestView.resumeAnimation()
    }
    
    func didEnterBackground()
    {
        self.regiestView.pauseAnimation()
    }
    
    // MARK: - 懒加载
    private lazy var regiestView: XSRegiestView = XSRegiestView()
}
